import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';


//导入三级跳转源页面
import {addTrenchPage} from '../addTrench'

//actionsheet需要导入的组件
import { Platform, ActionSheetController } from 'ionic-angular';
//接受从上个页面传递过来的数据
import { NavParams } from 'ionic-angular';
import {Http,Headers} from '@angular/http';
import {interfaceUrls} from '../../../../provider/serverUrls'
import 'rxjs/add/operator/toPromise';
import 'rxjs/add/operator/timeout';
//产品信息数据
import {ModalController, ViewController} from 'ionic-angular';
import {productPage2} from './productPage/productPage2'
@Component({
    selector: 'page-existDealer', 
    templateUrl: 'existDealer.html'
})
export class existDealerPage {
    data: any;
    companyName;     //公司名称
    textarea;       //详细地址信息
    remarks;        //对代理产品进行备注
    name;
    product;
    param={};
    private headers = new Headers({'Content-Type':'application/json;chartset=utf-8'});
   
    isShow:boolean;
    isNeed:boolean;
    constructor(public navCtrl: NavController,    
   			    public platform: Platform,
				public actionsheetCtrl: ActionSheetController,
                private navParams: NavParams,
                public http:Http,
    			public modalCtrl: ModalController
                

   			   ) 
	    {
//	    	 this.setCityPickerData();
             this.data = this.navParams.get('data');
             console.info(this.data);
			this.product = this.navParams.get('product')
        };

	addBack(){
		 this.navCtrl.pop();
	}
    addNext(){
    	
    }


  
      //选择代理酒产品的菜单  (click)="openMenu()"  方法

      //当前页面取消按钮的方法
      cancel(){
          this.navCtrl.popToRoot();
      }
  	  confirm(){
  	  	 this.http
		     .post(interfaceUrls.dealerAdd,
		     	 {
			        "companyName" : this.data.companyName,
			        "mobile" : this.data.mobile,
			        "name" : this.data.name,
			        "companyAddressId" : this.data.companyAddressId ,
			        "productId" : this.data.productId,
			        "remarks" :　this.remarks
			    }
		     	
		     ,{headers:this.headers})
		     .timeout(4000)
		     .toPromise()
		     .then((response) => {
		         console.info(response+"+++++++已存在经销商已添加到后台",this.remarks,this.data.companyAddressId
				 );
		         this.navCtrl.popToRoot();       //确定之后将数据添加到经销商页面
		     })
		     .catch((err)=>{console.info(err)})

//          console.info("====",this.areadata.city,this.areadata.city.value);
  	  	

  	  }
  	   openModal(characterNum) {

        let modal = this.modalCtrl.create(productPage2, {product: this.product});
        modal.present();
    }

  
}




